import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
import i18n from "@/i18n";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/oidc",
    component: () => import("@/views/login/oidc"),
    hidden: true,
  },
  {
    path: "/oidc_signout",
    component: () => import("@/views/login/oidc_signout"),
    hidden: true,
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: i18n.t("menus.dashboard"), icon: "dashboard" },
      },
    ],
  },
  {
    path: "/supply-chain",
    name: "Supplychain",
    component: Layout,
    meta: { title: "供应链", icon: "dashboard" },
    children: [
      {
        path: "purchase",
        name: "Purchase",
        component: () => import("@/views/supplychain/purchase/index"),
        meta: {
          title: "采购管理",
          icon: "iconfont icon-bank-account",
        },
        children: [
          {
            path: "product-price",
            name: "PurchaseProductPrice",
            component: () => import("@/views/supplychain/purchase/basicdata/productPrice/index.vue"),
            meta: { title: "采购价目列表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "product-price/edit",
            name: "PurchaseProductPriceEdit",
            component: () => import("@/views/supplychain/purchase/basicdata/productPrice/edit.vue"),
            meta: { title: "采购价目表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "requisition",
            name: "Purchaserequisition",
            component: () => import("@/views/supplychain/purchase/requisition/index"),
            meta: { title: "采购申请列表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "requisition-edit",
            name: "PurchaseRequisitionEdit",
            component: () => import("@/views/supplychain/purchase/requisition/edit"),
            meta: { title: "采购申请单", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "order",
            name: "PurchaseOrder",
            component: () => import("@/views/supplychain/purchase/order/index"),
            meta: { title: "采购订单列表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "order-edit",
            name: "PurchaseOrderEdit",
            component: () => import("@/views/supplychain/purchase/order/edit"),
            meta: { title: "采购订单", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
        ],
      }, {
        path: "sale",
        name: "Sale",
        component: () => import("@/views/supplychain/sale/index"),
        meta: {
          title: "销售管理",
          icon: "iconfont icon-bank-account",
        },
        children: [
          {
            path: "product-price",
            name: "SaleProductPrice",
            component: () => import("@/views/supplychain/sale/basicdata/productPrice/index.vue"),
            meta: { title: "销售目列表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "sale-quotation",
            name: "SaleQuotation",
            component: () => import("@/views/supplychain/sale/quotation/index.vue"),
            meta: { title: "销售报价列表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "sale-quotation/edit",
            name: "SaleQuotationEdit",
            component: () => import("@/views/supplychain/sale/quotation/edit.vue"),
            meta: { title: "销售报价单", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
          {
            path: "sale-order",
            name: "SaleOrder",
            component: () => import("@/views/supplychain/sale/basicdata/productPrice/index.vue"),
            meta: { title: "销售订单列表", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
        ]
      }, {
        path: "inventory",
        name: "Inventory",
        component: () => import("@/views/supplychain/inventory/index"),
        meta: {
          title: "库存管理",
          icon: "iconfont icon-bank-account",
        },
         children: [
          {
            path: "purchase-receipt",
            name: "PurchaseReceipt",
            component: () => import("@/views/supplychain/inventory/purchaseReceipt/index.vue"),
            meta: { title: "采购入库单", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
           {
            path: "purchase-receipt/edit",
            name: "PurchaseReceiptEdit",
            component: () => import("@/views/supplychain/inventory/purchaseReceipt/edit.vue"),
            meta: { title: "采购入库单", icon: "iconfont icon-bank-account" },
            hidden: true,
          },
        ]
      }]
  },
  {
    path: "/finance",
    name: "Finance",
    component: Layout,
    meta: { title: "财务管理", icon: "dashboard" },
    children: [
      {
        path: "/finance/bank",
        redirect: "/finance/bank",
        component: () => import("@/views/finance/index"),
        meta: {
          title: "基础资料",
          icon: "iconfont icon-bank-account",
        },
        children: [
          {
            path: "/finance/bank/index",
            name: "Bank",
            component: () => import("@/views/finance/bank/account/index"),
            meta: { title: "银行账号", icon: "iconfont icon-bank-account" },
          },
          {
            path: "banktype",
            name: "BankType",
            component: () => import("@/views/finance/bank/type/index"),
            meta: { title: "银行类型", icon: "iconfont icon-bank-account" },
          },
        ],
      },
      {
        path: "treasury",
        name: "Treasury",
        component: () => import("@/views/finance/treasury/index"),
        meta: {
          title: "出纳管理",
          icon: "iconfont icon-fapiao",
        },
        children: [
          {
            path: "payment-requisition",
            name: "PaymentRequisition",
            component: () => import("@/views/finance/treasury/paymentRequisition/index"),
            meta: { title: "付款申请单", icon: "iconfont icon-fapiao" },
            hidden: true,
          },
          {
            path: "payment-requisition/edit",
            name: "PaymentRequisitionEdit",
            component: () => import("@/views/finance/treasury/paymentRequisition/edit"),
            meta: { title: "付款申请单", icon: "iconfont icon-fapiao" },
            hidden: true,
          },
          {
            path: "payment",
            name: "Payment",
            component: () => import("@/views/finance/treasury/payment/index"),
            meta: { title: "付款单", icon: "iconfont icon-fapiao" },
            hidden: true,
          },
          {
            path: "payment/edit",
            name: "PaymentEdit",
            component: () => import("@/views/finance/treasury/payment/edit"),
            meta: { title: "付款单", icon: "iconfont icon-fapiao" },
            hidden: true,
          },
        ],
      },
      {
        path: "/gl",
        redirect: "/gl",
        meta: {
          title: "总账",
          icon: "iconfont icon-zongzhangguanli",
        },
        children: [
          {
            path: "journal",
            name: "Journal",
            component: () => import("@/views/finance/gl/journal/index"),
            meta: { title: "凭证", icon: "iconfont icon-pingzheng" },
          },
          {
            path: "journalEdit",
            component: () => import("@/views/finance/gl/journal/edit"),
            name: "JournalEdit",
            meta: {
              title: "凭证编辑",
              icon: "iconfont icon-opening-balance",
            },
            hidden: true,
          },
          {
            path: "settlement",
            name: "Settlement",
            component: () => import("@/views/finance/gl/settlement/index"),
            meta: { title: "结账", icon: "iconfont icon-jiezhang" },
          },
        ],
      },
      {
        path: "/report",
        component: Layout,
        redirect: "/report",
        meta: {
          title: "报表",
          icon: "iconfont icon-caiwubaobiao",
        },
        children: [
          {
            path: "accountbalance",
            name: "AccountBalanceReport",
            component: () => import("@/views/report/accountBalanceReport"),
            meta: {
              title: "科目余额表",
              icon: "iconfont icon-caiwubaobiao",
            },
          },
          {
            path: "subsidiaryLedger",
            name: "SubsidiaryLedgerReport",
            component: () => import("@/views/report/subsidiaryledgerReport"),
            meta: {
              title: "明细分类账",
              icon: "iconfont icon-caiwubaobiao",
            },
          },
          {
            path: "generalLedger",
            name: "GeneralLedgerReport",
            component: () => import("@/views/dashboard/index"),
            meta: { title: "总分类账", icon: "iconfont icon-caiwubaobiao" },
          },
        ],
      },
    ],
  },
  {
    path: "/basicdata",
    name: "Basicdata",
    component: Layout,
    meta: {
      title: "基础资料",
      icon: "iconfont icon-jichushuju",
    },
    children: [
      {
        path: "/basicdata/finance",
        name: "FinanceBasicData",
        redirect: "/basicdata/finance",
        component: () => import("@/views/basicdata/index"),
        meta: {
          title: "财务",
          icon: "iconfont icon-kemuguanli-",
        },
        children: [
          {
            path: "account",
            component: () => import("@/views/basicdata/finance/account/index"),
            name: "Account",
            meta: {
              title: "科目",
              icon: "iconfont icon-kemuguanli-",
            },
          },
          {
            path: "dimension",
            component: () =>
              import("@/views/basicdata/finance//dimension/index"),
            name: "Dimension",
            meta: {
              title: "核算维度",
              icon: "iconfont icon-duoweidu",
            },
          },
          {
            path: "endperiodprocessitem",
            component: () =>
              import("@/views/basicdata/finance/endPeriodProcessItem/index"),
            name: "EndPeriodProcessItem",
            meta: {
              title: "期末处理",
              icon: "iconfont icon-tag",
            },
          },
          {
            path: "openingBalance",
            component: () => import("@/views/basicdata/finance/openingBalance/index"),
            name: "OpeningBalance",
            meta: {
              title: "期初余额",
              icon: "iconfont icon-opening-balance",
            },
          },
          {
            path: "openingBalanceEdit",
            component: () => import("@/views/basicdata/finance/openingBalance/edit"),
            name: "OpeningBalanceEdit",
            meta: {
              title: "期初余额录入",
              icon: "iconfont icon-opening-balance",
            },
            hidden: true,
          },
          {
            path: "numberPrefix",
            component: () =>
              import("@/views/basicdata/finance/numberPrefix/index"),
            name: "JournalWord",
            meta: {
              title: "凭证字",
              icon: "iconfont icon-peizhiguanli",
            },
          },
        ],
      },
      {
        path: "/basicdata/trade",
        name: "TradeBasicData",
        redirect: "/basicdata/trade",
        component: () => import("@/views/basicdata/index"),
        meta: {
          title: "交易对象",
          icon: "iconfont icon-kemuguanli-",
        },
        children: [
          {
            path: "customer",
            component: () => import("@/views/basicdata/trade/customer/index"),
            name: "Customer",
            meta: {
              title: "客户",
              icon: "iconfont icon-kehuguanli",
            },
          },
          {
            path: "supplier",
            component: () => import("@/views/basicdata/trade/supplier/index"),
            name: "Supplier",
            meta: {
              title: "供应商",
              icon: "iconfont icon-supplier",
            },
          },
          {
            path: "emplyee",
            component: () => import("@/views/basicdata/trade/employee/index"),
            name: "Emplyee",
            meta: {
              title: "员工",
              icon: "iconfont icon-gongren",
            },
          },
        ],
      },

      {
        path: "product",
        component: () => import("@/views/basicdata/inventory/product/index"),
        name: "Product",
        meta: {
          title: "产品",
          icon: "iconfont icon-product",
        },
      },
      {
        path: "auxiliaryUnit",
        component: () => import("@/views/basicdata/inventory/auxiliaryunit/index"),
        name: "ProductAuxiliaryUnit",
        meta: {
          title: "辅助单位",
          icon: "iconfont icon-product",
        },
      },
      {
        path: "warehouse",
        component: () => import("@/views/basicdata/inventory/warehouse/index"),
        name: "Warehouse",
        meta: {
          title: "仓库",
          icon: "iconfont icon-product",
        },
      },
      {
        path: "taxrate",
        component: () => import("@/views/basicdata/taxrate/index"),
        name: "TaxRate",
        meta: {
          title: "税率",
          icon: "iconfont icon-trans",
        },
      },
      {
        path: "expenseItem",
        component: () => import("@/views/basicdata/other/expenseItem/index"),
        name: "ExpenseItem",
        meta: {
          title: "费用项目",
          icon: "iconfont icon-trans",
        },
      },
      // {
      //   path: "tag",
      //   component: () => import("@/views/basicdata/other/tag/index"),
      //   name: "Tag",
      //   meta: {
      //     title: "标签",
      //     icon: "iconfont icon-tag",
      //   },
      // },
      {
        path: "currency",
        component: () => import("@/views/basicdata/other/currency/index"),
        name: "Currency",
        meta: {
          title: "货币",
          icon: "iconfont icon-tag",
        },
      },
      {
        path: "unit",
        component: () => import("@/views/basicdata/unit/index"),
        name: "Unit",
        meta: {
          title: "单位",
          icon: "iconfont icon-tag",
        },
      },
    ],
  },
  {
    path: "/permission",
    component: Layout,
    redirect: "/permission",
    meta: {
      title: "权限管理",
      icon: "iconfont icon-xitongquanxian",
    },
    children: [
      {
        path: "/user/index",
        component: () => import("@/views/permission/user/index"),
        name: "User",
        meta: {
          title: i18n.t("menus.user"),
          icon: "iconfont icon-yonghu",
        },
      },
      {
        path: "/role/index",
        component: () => import("@/views/permission/role/index"),
        name: "Role",
        meta: {
          title: i18n.t("menus.role"),
          icon: "iconfont icon-jiaoseguanli",
        },
      },
      {
        path: "/department/index",
        component: () => import("@/views/permission/department/index"),
        name: "Department",
        meta: {
          title: "部门",
          icon: "iconfont icon-jiaoseguanli",
        },
      },
    ],
  },
  {
    path: "/setting",
    component: Layout,
    redirect: "/setting",
    meta: {
      title: "设置",
      icon: "iconfont icon-shezhi",
    },
    children: [
      {
        path: "organization",
        component: () => import("@/views/setting/organization/index"),
        name: "Organization",
        meta: {
          title: "组织",
          icon: "iconfont icon-gongsi",
        },
      },
      {
        path: "number-rule",
        component: () => import("@/views/setting/number-rule/index"),
        name: "NumberRule",
        meta: {
          title: "编码规则",
          icon: "iconfont icon-gongsi",
        },
      },
      {
        path: "configuration",
        component: () => import("@/views/setting/configuration"),
        name: "Configuration",
        meta: {
          title: "系统配置",
          icon: "iconfont icon-peizhiguanli",
        },
      },
      {
        path: "printTemplate",
        component: () => import("@/views/setting/printTemplate/index"),
        name: "PrintTemplate",
        meta: {
          title: "打印模板",
          icon: "iconfont icon-peizhiguanli",
        },
      },
    ],
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    mode: "history", // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
